<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
	<TITLE>Readme for hello example</TITLE>
	<META NAME="GENERATOR" CONTENT="OpenOffice.org 2.0  (Linux)">
	<META NAME="CREATED" CONTENT="20061007;13053000">
	<META NAME="CHANGEDBY" CONTENT="kejin">
	<META NAME="CHANGED" CONTENT="20071009;261900">
	<STYLE TYPE="text/css">
	<!--
		@page { size: 8.5in 11in }
		P { color: #000000 }
		H2 { color: #000000 }
		H3 { color: #000000 }
		PRE { color: #000000 }
		A:link { color: #0000ff }
		A:visited { color: #990066 }
	-->
	</STYLE>
</HEAD>
<BODY LANG="en-US" TEXT="#000000" LINK="#0000ff" VLINK="#990066" BGCOLOR="#ffffff" DIR="LTR">
<H2>PocoCapsule/C++ example: Basic-IoC Hello 
</H2>
<P>Copyright(c) 2006, 2007 by <A HREF="http://www.pocomatic.com/">Pocomatic
Software</A>. All rights reserved.</P>
<P>This example demonstrates several simplest forms of bean
instantiation management, lifecycle control, and IoC invocations
supported in PocoCapsule. 
</P>
<UL>
	<LI><P>The first scenario simply declares a C++ object of class <FONT FACE="Nimbus Mono L, monospace"><FONT COLOR="#944794">Foo</FONT></FONT>.
	It can be instantiated through its <FONT FACE="Nimbus Mono L, monospace"><FONT COLOR="#944794">Foo(const
	char*)</FONT></FONT> constructor (this is referred to as
	<I><FONT COLOR="#800080">&quot;constructor IoC&quot;</FONT></I>). A
	destroy method and a post-instantiation IoC method are also
	declared. The post-instantiation method is a member function
	<FONT FACE="Nimbus Mono L, monospace"><FONT COLOR="#944794">print(const
	char*)</FONT></FONT> of the bean, and is a special case of <I><FONT COLOR="#944794">&quot;setter
	IoC&quot;</FONT></I> or <I><FONT COLOR="#944794">&quot;bean member
	function IoC&quot;</FONT></I>. These IoC forms are expressed in the
	<A HREF="setup.xml">setup.xml</A> as follows:</P>
</UL>
<PRE>        <FONT FACE="Courier 10 Pitch"><FONT COLOR="#000080">&lt;bean <B><I>class=&quot;Foo&quot;</I></B></FONT></FONT>
<FONT COLOR="#000080">              <B><I><FONT FACE="Courier 10 Pitch">destroy-method=&quot;delete&quot;</FONT></I></B></FONT>
<FONT COLOR="#000080">              <FONT FACE="Courier 10 Pitch">lazy-init=&quot;false&quot;</FONT></FONT>
<FONT COLOR="#000080">              <FONT FACE="Courier 10 Pitch">depends-on=&quot;<B><I>do-this-first</I></B>&quot;&gt;</FONT></FONT>
<FONT COLOR="#000080">            <FONT FACE="Courier 10 Pitch">&lt;method-arg type=&quot;cstring&quot; value=&quot;Foo constructor!&quot;/&gt;</FONT></FONT>
<FONT COLOR="#000080">            <B><I><FONT FACE="Courier 10 Pitch">&lt;ioc method=&quot;hello&quot;&gt;</FONT></I></B></FONT>
<FONT COLOR="#000080">                 <FONT FACE="Courier 10 Pitch">&lt;method-arg type=&quot;cstring&quot; value=&quot;Foo hello()!&quot;/&gt;</FONT></FONT>
<FONT COLOR="#000080">            <FONT FACE="Courier 10 Pitch">&lt;/ioc&gt;</FONT></FONT>
<FONT COLOR="#000080">        <FONT FACE="Courier 10 Pitch">&lt;/bean&gt;</FONT></FONT></PRE>
<UL>
	<P>This description implies the following bean instantiation and
	post-instantiation operations:</P>
</UL>
<PRE>        <FONT FACE="Courier 10 Pitch"><FONT COLOR="#000080">Foo* the_bean = new Foo((const char*)&quot;Foo constructor!\n&quot;);   // when initSingletons() on the application context</FONT></FONT>
<FONT COLOR="#000080">        <FONT FACE="Courier 10 Pitch">the_bean-&gt;hello((const char*)&quot;Foo hello()!&quot;);</FONT></FONT></PRE><P STYLE="margin-left: 0.49in; text-indent: 0.01in">
The above instantiated singleton bean is put under life-cycle
control, because of the &quot;destroy-method&quot; attribute setting.
Therefore, this (singleton) bean will be destroyed using the
specified method on termination of the application context.</P>
<PRE><FONT COLOR="#000080">        <FONT FACE="Courier 10 Pitch">...</FONT></FONT>
<FONT COLOR="#000080">        <FONT FACE="Courier 10 Pitch">delete the_bean;       // when terminate() on the application context</FONT></FONT></PRE>
<UL>
	<LI><P>The above bean of class Foo has a pre-instantiation
	dependency on a bean of identified by <I>id</I> &quot;do-this-first&quot;.
	This dependent bean and all its post-instantiation invocations, as
	declared in the following XML stanza, are to be instantiated and
	invoked before the instantiation of the Foo bean:</P>
</UL>
<PRE>       <FONT COLOR="#000080"> <FONT FACE="Courier 10 Pitch">&lt;bean id=&quot;<B><I>do-this-first</I></B>&quot; class=&quot;void&quot;&gt;</FONT></FONT>
<FONT COLOR="#000080">            <FONT FACE="Courier 10 Pitch">&lt;ioc <B>method=&quot;printf&quot;</B>&gt;</FONT></FONT>
<FONT COLOR="#000080">               <FONT FACE="Courier 10 Pitch">&lt;method-arg type=&quot;cstring&quot; value=&quot;Hello %s\n&quot;/&gt;</FONT></FONT>
<FONT COLOR="#000080">               <FONT FACE="Courier 10 Pitch">&lt;method-arg type=&quot;cstring&quot; value=&quot;C stdio printf()!&quot;/&gt;</FONT></FONT>
<FONT COLOR="#000080">            <FONT FACE="Courier 10 Pitch">&lt;/ioc&gt;</FONT></FONT>

<FONT COLOR="#000080">            &lt;ioc <B><FONT FACE="Courier 10 Pitch">method=&quot;std::cout {{&quot;</FONT>&gt;</B></FONT>
               &lt;method-arg type=&quot;cstring&quot; value=&quot;Hello C++ std::cout!\n&quot;/&gt;
<FONT COLOR="#000080">            <FONT FACE="Courier 10 Pitch">&lt;/ioc&gt;</FONT></FONT>
<FONT COLOR="#000080">        <FONT FACE="Courier 10 Pitch">&lt;/bean&gt;</FONT></FONT></PRE>
<UL>
	<P>This void bean has two post-instantiation IoC methods. The &quot;void&quot;
	class of this bean implies these two methods are all C or C++ global
	functions. The first IoC method simply calls the C stdio printf()
	function with two string parameters. The second IoC method is a <I><FONT COLOR="#944794">&quot;C++
	operator IoC&quot;</FONT></I>, that invokes the C++ iostream's
	<FONT FACE="Nimbus Mono L, monospace"><FONT COLOR="#944794">operator&lt;&lt;()</FONT></FONT>
	on <FONT FACE="Nimbus Mono L, monospace"><FONT COLOR="#944794">std::cout</FONT></FONT>.
	These two &lt;ioc&gt; elements imply the following two invocation
	statements:</P>
</UL>
<UL>
	<PRE STYLE="margin-bottom: 0.2in"> <FONT COLOR="#000080"> <FONT FACE="Courier 10 Pitch">printf(&quot;Hello %s\n&quot;, &quot;C stdio printf()!&quot;);</FONT></FONT></PRE>
</UL>
<UL>
	<PRE STYLE="margin-bottom: 0.2in">  <FONT FACE="Courier 10 Pitch"><FONT COLOR="#000080">std::cout &lt;&lt; &quot;Hello C++ std::cout!\n&quot;; </FONT></FONT></PRE>
</UL>
<H3>Source Files</H3>
<P><A HREF="main.C">main.C:</A> This is a simple mini container, used
to deploy the example application. This container is completely
application logic independent. It contains no application specific
code. Its executable, after build, does not depends on (by linking
to) any application specific component modules (dynamic libraries).</P>
<P><A HREF="foo.h">foo.h</A> and <A HREF="foo.C">foo.C:</A> The
application logic bean component implementation. This application
logic implementation is a plain old C++ object. It does not contain
any container specific classes or code. 
</P>
<P><A HREF="setup.xml">setup.xml:</A> This is the application setup
description. It describes those IoC setups discussed above. 
</P>
<H3>Building this example</H3>
<P STYLE="font-weight: medium">To build this example, the environment
variable POCOCAPSULE_DIR should point to the PocoCapsule/C++
installed directory. Then, this example can be built by simply
invoking gmake/make on linux/unix or nmake on windows. 
</P>
<H3>Running this example</H3>
<P><FONT FACE="Symbol">&middot; </FONT><FONT FACE="Times New Roman">Before
starting the application deployment container (i.e. the main
executable), make sure the LD_LIBRARY_PATH (on linux and solaris) or
the PATH (on windows) environment variable is set correctly to
include the ${POCOCAPSULE_DIR}/lib directory.</FONT></P>
<P><FONT FACE="Symbol">&middot; </FONT><FONT FACE="Times New Roman">start
the main executable: </FONT>
</P>
<PRE STYLE="margin-left: 0.79in; margin-bottom: 0.2in"><B>prompt&gt;</B> main </PRE><P STYLE="margin-bottom: 0.2in">
<FONT FACE="Times New Roman">It will print out the following result:</FONT></P>
<PRE STYLE="margin-left: 0.79in">Hello C stdio printf()!
Hello C++ std::cout!
Hello Foo constructor!
Hello Foo print()!
That's all folks! Goodbye!</PRE><P STYLE="margin-bottom: 0.2in">
<A HREF="../../README.html">Back to the root page</A></P>
</BODY>
</HTML>